﻿@model CategoriesWidgetModel
@{
	List<Category> expanded = (List<Category>)ViewData["Expanded"];
}

@if (Model.Categories.Count() > 0)
{
	<ul class="@(Model.Expanded ? "" : "hidden")" @(Model.Expanded ? "data-expanded='true'".AsHtml() : null)>
		@foreach (var cat in Model.Categories)
		{
			bool hasSubCategories = cat.SubCategories.Count > 0;
			bool isExpanded = expanded != null && expanded.Any(r => r.Id == cat.Id);
			<li>
				<a href="#" class="pin" style="@(hasSubCategories ? "" : "visibility: hidden")"><img alt="@(isExpanded? "закрыть" : "открыть")" src="@(isExpanded ? "/Content/Icons/toggle_collapse.png" : "/Content/Icons/toggle.png")" /></a>
				<a href="@Url.Action("Index", new { parentId = cat.Id })">@cat.Title</a>
				@if (hasSubCategories)
				{
					@Html.Partial("CategoriesWidgetInner", new CategoriesWidgetModel(cat.SubCategories, isExpanded))
				}
			</li>
		}
	</ul>
}